package jay.home.templates;

import java.util.*;
import jay.home.utils.*;

public class StrutsConfigTemplate
{
  protected static String nl;
  public static synchronized StrutsConfigTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    StrutsConfigTemplate result = new StrutsConfigTemplate();
    nl = null;
    return result;
  }

  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + NL + "<!DOCTYPE struts-config PUBLIC" + NL + "          \"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN\"" + NL + "          \"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd\">" + NL + "" + NL + "<struts-config>" + NL + "" + NL + "" + NL + "<form-beans>";
  protected final String TEXT_2 = NL + "\t<form-bean name=\"";
  protected final String TEXT_3 = "Form\" type=\"jay.home.bet.web.struts.";
  protected final String TEXT_4 = "ActionForm\" />";
  protected final String TEXT_5 = NL + "</form-beans>" + NL + "" + NL + "<global-forwards>" + NL + "\t\t<forward name=\"error\" path=\"/WEB-INF/jsp/error.jsp\" redirect=\"false\"/>" + NL + "\t\t<forward name=\"failure\" path=\"/WEB-INF/jsp/error.jsp\" redirect=\"false\"/>" + NL + "\t\t<forward name=\"unknown-error\" path=\"/WEB-INF/jsp/error.jsp\"/>" + NL + "</global-forwards>" + NL + "" + NL + "" + NL + "<action-mappings>" + NL + "" + NL + "<action forward=\"/WEB-INF/jsp/error.jsp\" path=\"/error\" />";
  protected final String TEXT_6 = NL + "\t<action forward=\"/WEB-INF/jsp/";
  protected final String TEXT_7 = "/";
  protected final String TEXT_8 = ".jsp\" path=\"/";
  protected final String TEXT_9 = "/to";
  protected final String TEXT_10 = "\" />" + NL + "\t<action path=\"/";
  protected final String TEXT_11 = "/";
  protected final String TEXT_12 = "\" type=\"jay.home.bet.web.struts.";
  protected final String TEXT_13 = "Action\"" + NL + "\t\tname=\"";
  protected final String TEXT_14 = "Form\" >" + NL + "\t\t<forward name=\"success\" path=\"/WEB-INF/jsp/";
  protected final String TEXT_15 = "/index.jsp\" />" + NL + "\t\t<forward name=\"failure\" path=\"/WEB-INF/jsp/";
  protected final String TEXT_16 = "/index.jsp\" />" + NL + "\t</action>";
  protected final String TEXT_17 = NL + "</action-mappings>" + NL + "" + NL + "</struts-config>";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
  Map<String, List<String>> map = (Map<String, List<String>>)argument;
  String[] types = new String[]{"common", "user", "mgr", "admin"};

    stringBuffer.append(TEXT_1);
    
for(String type : types)
{
  for(String item : map.get(type))
  {

    stringBuffer.append(TEXT_2);
    stringBuffer.append(item);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(StringUtils.capitalize(item));
    stringBuffer.append(TEXT_4);
      	
  }
}

    stringBuffer.append(TEXT_5);
    
for(String type : types)
{
	for(String item : map.get(type))
	{

    stringBuffer.append(TEXT_6);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_7);
    stringBuffer.append(item);
    stringBuffer.append(TEXT_8);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_9);
    stringBuffer.append(item);
    stringBuffer.append(TEXT_10);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_11);
    stringBuffer.append(item);
    stringBuffer.append(TEXT_12);
    stringBuffer.append(StringUtils.capitalize(item));
    stringBuffer.append(TEXT_13);
    stringBuffer.append(item);
    stringBuffer.append(TEXT_14);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_15);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_16);
      	
	}
}

    stringBuffer.append(TEXT_17);
    return stringBuffer.toString();
  }
}
